<html>
<head>
 <meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body>
<script type="text/javascript" src="rules.js"></script>
<script type="text/javascript">

// override newline
rules['NEWLINE'] = [ '<br>' ];

// IE fix: in IE, [1,2,3,] has length == 4 due to trailing comma
if (navigator.userAgent.indexOf("MSIE") >= 0) {
	for (var k in rules) {
		var tmp = rules[k];
		rules[k] = [];
		for (var i = 0 ; i < tmp.length; i ++ )
			if (tmp[i] != undefined) rules[k].push(tmp[i]);
	}
}

function cfggen(tokens) {
  var a = tokens.split(' ');
  var ret = [];
  for (var i = 0; i < a.length; ++i) {
	var c = a[i].charAt(0);
	if (c >= 'A' && c <= 'Z') {
		var k = Math.floor(Math.random() * rules[a[i]].length);
		ret.push(cfggen(rules[a[i]][k]));
	}
	else
		ret.push(a[i]);
  }
  return ret.join(' ');
}

document.write(cfggen('POEM'));

</script>
</body>
</html>
